export default async function api(url, data = '') {
	var [error, res] = await uni.request({
		url: 'http://10.253.1.246:8181/' + url, //仅为示例，并非真实接口地址。
		method: data ? 'POST' : 'GET',
		data,
		header: {
			'content-type': 'application/x-www-form-urlencoded' //自定义请求头信息
		}
	});

	if (res.statusCode === 200) {
		if (res.data.status === '0') {
			uni.showToast({
				title: res.data.msg,
				duration: 2000,
				icon: 'none'
			});
			return Promise.reject(res.data.msg)
		} else if (res.data.status === '1') {
			uni.showToast({
				title: '请先登录',
				duration: 2000,
				icon: 'none'
			});
			uni.navigateTo({
				url: 'login'
			})
			return Promise.reject(res.data.msg)
		} else {
			return Promise.resolve(res.data.data)
		}

	} else {
		uni.showToast({
			title: '网络错误',
			duration: 2000,
			icon: 'none'
		});
		return Promise.reject('网络错误')
	}
}
